package com.zzb.learning.api;

import com.zzb.base.model.PageResult;
import com.zzb.learning.model.dto.MyCourseTableParams;
import com.zzb.learning.model.dto.XcChooseCourseDto;
import com.zzb.learning.model.dto.XcCourseTablesDto;
import com.zzb.learning.model.po.XcCourseTables;
import com.zzb.learning.service.CourseTablesService;
import com.zzb.learning.service.XcChooseCourseService;
import com.zzb.learning.util.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Mr.M
 * @version 1.0
 * @description 我的课程表接口
 * @date 2022/10/25 9:40
 */

@Api(value = "我的课程表接口", tags = "我的课程表接口")
@Slf4j
@RestController
public class CourseTablesController {
    @Autowired
    private XcChooseCourseService xcChooseCourseService;
    @Autowired
    private CourseTablesService courseTablesService;

    @ApiOperation("添加选课")
    @PostMapping("/choosecourse/{courseId}")
    public XcChooseCourseDto addChooseCourse(@PathVariable("courseId") Long courseId) {
        SecurityUtil.XcUser xcUser = SecurityUtil.getUser();
        if (xcUser == null) {
            throw new RuntimeException("请登录后再添加选课");
        }
        XcChooseCourseDto xcChooseCourseDto = xcChooseCourseService.addChooseCourse(courseId, xcUser.getId());
        return xcChooseCourseDto;
    }

    @ApiOperation("查询学习资格")
    @PostMapping("/choosecourse/learnstatus/{courseId}")
    public XcCourseTablesDto getLearnstatus(@PathVariable("courseId") Long courseId) {
        SecurityUtil.XcUser xcUser = SecurityUtil.getUser();
        if (xcUser == null) {
            throw new RuntimeException("请先登录");
        }
        XcCourseTablesDto xcCourseTablesDto = courseTablesService.getLearnstatus(xcUser.getId(), courseId);
        return xcCourseTablesDto;
    }

    @ApiOperation("我的课程表")
    @GetMapping("/mycoursetable")
    public PageResult<XcCourseTables> mycoursetable(MyCourseTableParams params) {
        PageResult<XcCourseTables> xcCourseTablesPageResult =  courseTablesService.courseTable(params);
        return xcCourseTablesPageResult;
    }

}
